/*
 * Author: yezi
 * E-mail: okye328@gmail.com
 * Create time: Dec 22, 2012 12:01:38 AM
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */

package com.kanbox.linux.token;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class URLExtractor {

	private static Logger logger = LoggerFactory.getLogger(URLExtractor.class);

	private String url;

	private Map<String, String> map = new HashMap<String, String>();

	public URLExtractor(String url) {
		this.url = url;

		int index = this.url.indexOf("?");
		if (index < 0) {
			try {
				throw new Exception("This url dose not contain parameter");
			} catch (Exception e) {
				logger.error(e.getLocalizedMessage(), e);
			}
		}
		String subString = this.url.substring(index).replace("?", "");
		String[] splits = subString.split("&");
		for (String s : splits) {
			int i = s.indexOf("=");
			String key = s.substring(0, i);
			String value = s.substring(i).replace("=", "");
			map.put(key, value);
		}
	}

	public String getString(String key) {
		return map.get(key);
	}
}
